home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char SccsId[]= "@(#)dp_create.c V1.21 3/22/95";
- #endif
-
- /*
- | file name dp_create.c
- |===================================================================
- |
- | This program shows how to create drawports based on a layout
- | file created in DV-Draw.
- |
- | This program loads a layout file, extracts named rectangles
- | and uses their world coordinates to determine where to
- | create drawports. This program assumes that the "areas" were
- | defined relative to the whole world. That is, in DV-Draw,
- | the user "Zoomed Out" until the whole world was visible,
- | this "world" maps to the "screen" and the "areas" map to the
- | "vvp" to use when creating the drawport. The whole view will
- | be "stretched" to fit into the drawports.
- |
- | The program displays the views and waits for the user to
- | quit by selecting a <q|Q> key, the right mouse button, or
- | an object named "quit".
- |
- |===================================================================
- */
- #include <windows.h>
-
-
- /* DV-Tools header files */
- #include "std.h" /* <stdio.h> etc., scalar & macro definitions */
- #include "dvstd.h" /* public types & constants */
- #include "dvtools.h" /* constants used by T routines */
- #include "dvGR.h" /* constants used by window mgt & GR routines */
- #include "VOstd.h" /* constants used by VO & VOob routines */
- #include "Tfundecl.h" /* T routines (screens, drawports & views) */
- #include "VOfundecl.h" /* VO routines (objects) */
- #include "VUerfundecl.h" /* VUer routines (event handling routines) */
-
-
- /* Constants */
- #define DVPATH (char *)NULL
- #define DISPFORMS_STB (char *)NULL
- #define DVDEVICE (char *)NULL
- #define DVCOLORTABLE (char *)NULL
- #define SCREEN_VIEWPORT (RECTANGLE *)NULL
- #define DRAWING_VIEWPORT (RECTANGLE *)NULL
-
- #define NUM_DRAWPORTS 2
-
- /* Define & initialize names of screen, view files, layout file, and area */
- LOCAL char *device_name = DVDEVICE;
- LOCAL char *view_name[NUM_DRAWPORTS] =
- {
- "play.v",
- "message.v",
- };
- LOCAL char *layout_name = "dp.lay";
- LOCAL char *area_name[NUM_DRAWPORTS] =
- {
- "main.area",
- "message.area",
- };
-
- /* Whole world rectangle, (-16384, -16384) to (16383, 16383)*/
- LOCAL RECTANGLE whole_world =
- {XMIN, YMIN, XMAX, YMAX};
-
-
- /*
- * MAIN PROGRAM
- */
- int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow )
- {
- INT argc = 0;
- CHAR **argv;
-
- /* program arguments
- * argv[1] - display device (default is DVDEVICE)
- */
-
- /* Define display variables */
- OBJECT screen; /* display device, the window */
- DRAWPORT drawport[NUM_DRAWPORTS]; /* how & where to display each picture */
- VIEW layout_view, /* representation of the view with
- rectangular layout areas */
- view[NUM_DRAWPORTS]; /* picture representation of
- each view file */
-
- /* Control loop variables */
- OBJECT location; /* cursor position details */
- OBJECT layout_dr; /* graphical portion of the layout view */
- int i; /* an index variable */
- int event_status; /* how the event handler has used the
- location event */
-
- /* Layout rectangle variables */
- RECTANGLE box, /* world coordinate drawport area */
- svp_delta, /* allowance for line thickness */
- vvp; /* virtual coordinate drawport area */
- char *obj_name; /* name of object at location */
-
- /* Other variables */
- int Quit = NO; /* flag to quit program */
-
-
-
-
- /*--------------------
- * Initialization
- *
- * TInit: perform the initialization of DV-Tools
- * TInit reads your configuration file and any
- * environment variables or logical names set.
- */
- make_argv(&argc,&argv,GetCommandLine());
- TInit (DVPATH, DISPFORMS_STB);
-
- /*
- * TscOpenSet: open a device as a screen object using
- * specified attributes
- * TscErase: erase the entire screen in the default
- * background color
- *
- * Set exposure block to YES to insure the window
- * is ready for drawing when TdpDraw is called.
- */
- if (argc > 1)
- device_name = argv[1];
- screen = TscOpenSet (device_name, DVCOLORTABLE,
- V_X_EXPOSURE_BLOCK, YES,
- V_ACTIVE_CURSOR, V_END_OF_LIST);
- if (!screen)
- {
- printf ("Must specify device on command line or");
- printf (" in DataViews configuration file.\n");
- S_EXIT (EXIT_ERR);
- }
- TscErase (screen);
-
- /*
- * VOscWinEventMask: sets the screen's window event mask
- */
- VOscWinEventMask ((ULONG) V_KEYPRESS | V_BUTTONPRESS |
- V_EXPOSE | V_RESIZE | V_MOTIONNOTIFY,
- (ULONG) 0);
-
- /*
- * TviLoad: Load a view from a file, the layout file
- * TviGetDrawing: Gets drawing object
- * which TviLoad created as part of the view structure
- */
- layout_view = TviLoad (layout_name);
- if (!layout_view)
- {
- printf ("Could not load view from file ");
- printf ("%s.\n", layout_name);
- S_EXIT (EXIT_ERR);
- }
- layout_dr = TviGetDrawing (layout_view);
-
- /* Create and display drawports */
- for (i = 0; i < NUM_DRAWPORTS; i++)
- {
- /*
- * TviLoad: Load a view in from a file, a view file
- */
- view[i] = TviLoad (view_name[i]);
- if (!view[i])
- {
- printf ("Could not load view from file ");
- printf ("%s.\n", view_name[i]);
- S_EXIT (EXIT_ERR);
- }
-
- /*
- * TdrGetNamedObject: Get a named object from a drawing
- * VOobBox: Get an object's bounding box
- * gets the rectangular area where the drawport
- * will be shown (may ignore svp_delta in this case)
- */
- VOobBox (TdrGetNamedObject (layout_dr, area_name[i]), &box, &svp_delta);
-
- /* Since the "world coordinates" are -16K to 16K and the
- * "virtual screen coordinates" are 0K to 32K
- * simply add +/- 16K to box (world) to obtain vvp (virtual)
- */
- vvp.ll.x = box.ll.x + XMAX;
- vvp.ll.y = box.ll.y + YMAX;
- vvp.ur.x = box.ur.x + XMAX;
- vvp.ur.y = box.ur.y + YMAX;
-
- /*
- * Create the drawport
- * TdpCreateStretch: Create a DV-tools window, a drawport
- * "drawport" is attached to the screen object, "screen"
- * "view[i]" is the view to be displayed on the screen
- * "vvp" specifies the screen viewport, here the
- * rectangular area named area_name[i]
- * "whole_world" specifies the portion of the view to be
- * displayed, here the whole view
- * The whole view will be stretched to fit in the drawport
- */
- drawport[i] = TdpCreateStretch (screen, view[i], &vvp, &whole_world);
-
- /*
- * TviOpenData: Open all data source lists for this view and views
- * referenced by enabled subdrawings contained in view
- * TviReadData: Reads data from the data sources of a view
- * TdpDraw: Draw the contents of a drawport
- */
- TviOpenData (view[i]);
- TviReadData (view[i]);
- TdpDraw (drawport[i]);
- }
-
-
- /*--------------------
- * Control Loop
- *
- * Poll the event queue for window events specified by the
- * window mask. Handle each of the events as they happen.
- * Events occurring within input objects will be handled
- * through the event request handler VUerHandleLocEvent.
- * Draw successive updates of the view after reading a data
- * iteration. Stop when the user selects "q|Q", the
- * right mouse button, or selects an object named "quit".
- */
- FOREVER
- {
- /*
- * VOloWinEventPoll: Poll for the next window event.
- * The polling mode used is V_NO_WAIT.
- * Using this mode, VOloWinEventPoll
- * does not wait until a masked event
- * is generated.
- *
- * VUerHandleLocEvent: Service the event. This routine will check
- * if the event is used by any input objects
- * such as the slider in play.v.
- */
- location = VOloWinEventPoll (V_NO_WAIT);
- if (location)
- {
- event_status = VUerHandleLocEvent (location);
-
- /*
- * If the return value of VUerHandleLocEvent is INPUT_UNUSED
- * then check for keypress or buttonpress events which
- * represent one of the exit keys as well as checking if
- * an object was selected which has a name of "quit".
- */
- if (event_status == INPUT_UNUSED)
- {
- /*
- * VOloType: returns the type of event. These types
- * match event types specified in VOscWinEventMask.
- */
- switch (VOloType (location))
- {
-
- case V_RESIZE:
- /*
- * The window size has been changed.
- * TscReset: Resets all screen drawports after
- * window resizing
- */
- TscReset (screen);
- break;
-
- case V_EXPOSE:
- /*
- * VOloRegion: Returns a rectangle representing the
- * exposed region on the screen.
- * TscRedraw: After erasing, redraws all the drawports
- * in the screen.
- * A portion of the window has been exposed and needs
- * to be redrawn.
- */
- TscRedraw (screen, VOloRegion (location));
- break;
-
- case V_KEYPRESS:
- /*
- * Check key selected.
- *
- * VOloKeySym: Returns the key symbol value of
- * the location object
- * TloGetSelectedObjectName: Get the name of the selected
- * object
- *
- * If the key symbol represents the characters 'q'
- * or 'Q' then quit the program.
- * Any ascii key acts as a possible selection key. A
- * selected object with the name "quit" exits the program.
- */
- switch (VOloKeySym (location))
- {
- case 'q':
- case 'Q':
- Quit = YES;
- break;
-
- default:
- if ((obj_name = TloGetSelectedObjectName (location)) &&
- (strcmp (obj_name, "quit") == 0))
- Quit = YES;
- break;
- }
- break;
-
- case V_BUTTONPRESS:
- /*
- * Check button selected.
- *
- * VOloButton: Returns button that was pressed
- * TloGetSelectedObjectName: Get name of the selected object
- *
- * The left mouse button acts as the selection button. A
- * selected object with the name "quit" signifies the exit
- * of the program. The right mouse button exits the program.
- */
- switch (VOloButton (location))
- {
- case 1:
- if ((obj_name = TloGetSelectedObjectName (location)) &&
- (strcmp (obj_name, "quit") == 0))
- Quit = YES;
- break;
-
- case 3:
- Quit = YES;
- break;
-
- default:
- break;
- }
- break;
-
- case V_MOTIONNOTIFY:
- default:
- break;
- }
- }
- }
-
- /* exit the program */
- if (Quit == YES)
- break;
-
- /*
- * TviReadData: Read data from the data sources of the view.
- * TdpDrawNext: Update all dynamic objects within a drawport's view
- */
- for (i = 0; i < NUM_DRAWPORTS; i++)
- {
- TviReadData (view[i]);
- TdpDrawNext (drawport[i]);
- }
- }
-
-
- /*--------------------
- * Termination
- *
- * TscErase: Erase the entire screen in the default
- * background color
- * TdpDestroy: Destroy the drawport,
- * TviCloseData: Close the data sources of the view
- * TviDestroy: Destroy the view, freeing the allocated memory
- * TscCloseCurrentScreen: Close the current display screen
- * TTerminate: Perform the clean-up for DV-Tools
- */
- TscErase (screen);
- for (i = 0; i < NUM_DRAWPORTS; i++)
- {
- TdpDestroy (drawport[i]);
- TviCloseData (view[i]);
- TviDestroy (view[i]);
- }
- TscCloseCurrentScreen ();
- TTerminate ();
- return EXIT_OK;
- }
-